//
//  ZLAlertLine.swift
//  ZLAlert
//
//  Created by 赵振磊 on 2022/11/27.
//

import Foundation

/// 其他
extension ZLAlert {
    /// 添加横线
    /// - Returns: ZLAlert
    @discardableResult
    public func addLine() -> ZLAlert {
        return self.addLine(ZLAlertConfig.shared.lineConfig)
    }
    /// 添加横线
    /// - Parameter config: 配置
    /// - Returns: ZLAlert
    @discardableResult
    public func addLine(_ config: ZLAlertItemConfig) -> ZLAlert {
        let lastView = self.mainView.subviews.last
        let line = UIView()
        line.backgroundColor = config.backgroundColor
        self.mainView.addSubview(line)
        line.snp.makeConstraints { make in
            make.left.equalTo(self.mainView).offset(config.insets.left)
            make.right.equalTo(self.mainView).offset(-config.insets.right)
            if (lastView == nil) {
                make.top.equalTo(self.mainView).offset(config.insets.top)
            } else {
                make.top.equalTo(lastView!.snp.bottom).offset(config.insets.top)
            }
            make.height.equalTo(config.height)
        }
        return self.layoutMainView(10)
    }
    /// 添加空隙
    /// - Parameter height: 高度
    /// - Returns: ZLAlert
    @discardableResult
    public func addSpace(height: CGFloat) -> ZLAlert  {
        let lastView = self.mainView.subviews.last
        let space = UIView()
        space.backgroundColor = .clear
        self.mainView.addSubview(space)
        space.snp.makeConstraints { make in
            make.left.right.equalTo(self.mainView)
            if (lastView == nil) {
                make.top.equalTo(self.mainView)
            } else {
                make.top.equalTo(lastView!.snp.bottom)
            }
            make.height.equalTo(height)
        }
        return self.layoutMainView(0)
    }
}
